#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int ret;
int n;
int m;
void dfs(vector<vector<char>>& grid, int i, int j)
{
    for (int k = 0; k < 4; k++)
    {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x >= 0 && x < n
            && y >= 0 && y < m
            && grid[x][y] == '1')
        {
            grid[x][y] = '0';
            dfs(grid, x, y);
        }
    }
}
int numIslands(vector<vector<char>>& grid)
{
    n = grid.size();
    m = grid[0].size();
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (grid[i][j] == '1')
            {
                grid[i][j] = '0';
                ret++;
                dfs(grid, i, j);
            }
        }
    }
    return ret;
}

int main()
{
	vector<vector<char> > v = {
		{'1','1','0','0','0'},
		{'1','1','0','0','0'},
		{'0','0','1','0','0'},
		{'0','0','0','1','1'}
	};

	cout << numIslands(v) << endl;
	return 0;
}